package com.iknow;

import com.iknow.data.QingboType;
import com.iknow.http.HttpException;
import com.iknow.http.Response;
import com.iknow.util.Loger;
import com.iknow.util.StringUtil;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class QingboResponse extends IKnowResponse
{
  private static final long serialVersionUID = -127781630L;
  private final String TAG = "QingboResponse";
  private String mAuthorImageID;
  private String mAuthorJid;
  private String mCommentCount;
  private Date mCreateDate;
  private String mDisplayName;
  private String mFavCount;
  private String mHot;
  private String mID;
  private String mSubject;
  private String mTags;
  private String mThumbnailUrl;
  private String mTitle;
  private QingboType mType;

  public QingboResponse(Response paramResponse)
    throws HttpException
  {
    super(paramResponse);
    JSONObject localJSONObject = paramResponse.asJSONObject();
    try
    {
      init(localJSONObject);
      return;
    }
    catch (JSONException localJSONException)
    {
      Loger.e("QingboResponse", "Create QingboResponse error:" + localJSONException.getMessage());
      localJSONException.printStackTrace();
    }
  }

  public QingboResponse(JSONObject paramJSONObject)
    throws HttpException
  {
    try
    {
      init(paramJSONObject);
      return;
    }
    catch (JSONException localJSONException)
    {
      Loger.e("QingboResponse", "Create QingboResponse error:" + localJSONException.getMessage());
      localJSONException.printStackTrace();
    }
  }

  public static List<QingboResponse> QingboResponses(Response paramResponse)
    throws HttpException
  {
    JSONArray localJSONArray;
    try
    {
      localJSONArray = paramResponse.asJSONArray();
      ArrayList localArrayList = new ArrayList(localJSONArray.length());
      int i = 0;
      if (i >= localJSONArray.length())
        return localArrayList;
      localArrayList.add(new QingboResponse(localJSONArray.getJSONObject(i)));
      ++i;
    }
    catch (JSONException localJSONException)
    {
      throw new HttpException(localJSONException);
    }
  }

  private String getTags(JSONArray paramJSONArray)
  {
    StringBuilder localStringBuilder = new StringBuilder();
    int i = 0;
    if (i >= paramJSONArray.length())
    {
      int j = localStringBuilder.length();
      if (j > 0)
        localStringBuilder.deleteCharAt(j - 1);
      return localStringBuilder.toString();
    }
    try
    {
      localStringBuilder.append(paramJSONArray.getString(i)).append(",");
      ++i;
    }
    catch (JSONException localJSONException)
    {
      while (true)
        localJSONException.printStackTrace();
    }
  }

  private void init(JSONObject paramJSONObject)
    throws JSONException, HttpException
  {
    JSONObject localJSONObject;
    if (paramJSONObject.has("content"))
    {
      localJSONObject = (JSONObject)paramJSONObject.get("content");
      this.mID = localJSONObject.getString("id");
      this.mTitle = localJSONObject.getString("name");
      this.mSubject = localJSONObject.getString("des");
      if (!(StringUtil.isEmpty(this.mSubject)))
        this.mSubject = this.mSubject.replace("\r\n", "\n");
      this.mHot = localJSONObject.getString("open_count");
      this.mFavCount = localJSONObject.getString("favorite_count");
      this.mCommentCount = localJSONObject.getString("comment_count");
      this.mType = QingboType.formString(localJSONObject.getString("type"));
      this.mThumbnailUrl = localJSONObject.getString("image_url");
      this.mCreateDate = parseDate(localJSONObject.getString("create_time"), "yyyy-MM-dd HH:mm:ss");
      this.mAuthorImageID = localJSONObject.getString("user_photo");
      this.mAuthorJid = localJSONObject.getString("user_id");
      this.mDisplayName = localJSONObject.getString("user_name");
      if (!(localJSONObject.has("tags")))
        break label201;
      this.mTags = getTags(localJSONObject.getJSONArray("tags"));
    }
    while (true)
    {
      while (true)
      {
        return;
        localJSONObject = paramJSONObject;
      }
      label201: this.mTags = "测试";
    }
  }

  public String getAuthorHeadImage()
  {
    return this.mAuthorImageID;
  }

  public String getAuthorID()
  {
    return this.mAuthorJid;
  }

  public String getAuthorName()
  {
    return this.mDisplayName;
  }

  public String getCommentCount()
  {
    return this.mCommentCount;
  }

  public Date getCreateTime()
  {
    return this.mCreateDate;
  }

  public String getFavoriteCount()
  {
    return this.mFavCount;
  }

  public String getHot()
  {
    return this.mHot;
  }

  public String getID()
  {
    return this.mID;
  }

  public String getSubject()
  {
    return this.mSubject;
  }

  public String getTags()
  {
    return this.mTags;
  }

  public String getThumbnailUrl()
  {
    return this.mThumbnailUrl;
  }

  public String getTitle()
  {
    return this.mTitle;
  }

  public QingboType getType()
  {
    return this.mType;
  }
}